/*
 * @Author: wangdazhuang
 * @Date: 2024-12-03 09:12:34
 * @LastEditTime: 2025-01-24 21:41:43
 * @LastEditors: wangdazhuang
 * @Description: 
 * @FilePath: /pornhub_app/lib/views/player/views/stop_ad.dart
 */

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pornhub_app/utils/extension.dart';

import '../../../components/image_view.dart';
import '../../../utils/ad_jump.dart';
import '../controllers/video_play_controller.dart';

class StopAd extends StatelessWidget {
  final VideoPlayController vc;
  const StopAd({super.key, required this.vc});

  _buildAd() {
    return SizedBox(
      width: 230.w,
      height: 135.w,
      child: ImageView(
        src: vc.stopAd?.adImage ?? '',
        fit: BoxFit.fill,
        clipWidth: null,
      ),
    ).onOpaqueTap(() {
      final ad = vc.stopAd!;
      kAdjump(ad, ad.adId ?? 0);
    });
  }

  _buldClose() {
    return Icon(
      Icons.cancel_outlined,
      color: Colors.white,
      size: 25.w,
    ).onTap(() {
      vc.toggleShowStopAd();
    }).marginLeft(12.w);
  }

  @override
  Widget build(BuildContext context) {
    if (vc.stopAd == null) return const SizedBox.shrink();
    if (!vc.showStopAd) return const SizedBox.shrink();
    return Positioned.fill(
      child: Container(
        color: Colors.black.withOpacity(0.6),
        alignment: Alignment.center,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [_buildAd(), _buldClose()],
        ),
      ),
    );
  }
}
